package pers.dzk.fivelnarow.config;

import pers.dzk.fivelnarow.config.util.ResourcesPath;

import javax.swing.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author 丁泽凯
 */
public class CheckerboardConfig {
    public static Properties pro;
    public static Map<String,ImageIcon> skins = new HashMap();
    static {
        pro = new Properties();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(ResourcesPath.CONFIG_PATH+"/Checkerboard.properties"), StandardCharsets.ISO_8859_1));
            pro.load(br);
            BufferedReader br2 = new BufferedReader(new InputStreamReader(new FileInputStream(ResourcesPath.CONFIG_PATH+"/Checkerboard"),StandardCharsets.UTF_8
            ));
            String str;
            while ((str = br2.readLine()) != null){
                String[] s = str.split(" ");
                skins.put(s[1],new ImageIcon(ResourcesPath.IMG_PATH+"/checkerboard/"+s[0]));
                System.out.println("棋盘地址："+new ImageIcon(ResourcesPath.IMG_PATH+"/checkerboard/"+s[0])+"皮肤名称"+s[1]);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static int getWidth(){
        return Integer.parseInt(pro.getProperty("Width"));
    }
    public static int getHeight(){
        return Integer.parseInt(pro.getProperty("Height"));
    }
    public static int getLineCount(){
        return Integer.parseInt(pro.getProperty("LineCount"));
    }
    public static int getLineDistance(){
        return Integer.parseInt(pro.getProperty("LineDistance"));
    }
    public static ImageIcon getSkin(String name){
        return skins.get(name);
    }
    public static Map<String,ImageIcon> getSkins(){
        return skins;
    }
}
